//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_fillAmmoBox.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_box","_side","_ammo_filled","_ammo_list"];
DEFAULT_PARAM(_box,0,objNull);
DEFAULT_PARAM(_side,1,BTC_side);
_ammo_filled = false;
_ammo_list = missionNameSpace getVariable [format["BTC_mobile_ammo_list_%1",_side],BTC_mobile_ammo_list];
if (count _ammo_list > 0) then {
	if (!isDedicated) then {
		{
			_class = _x select 0;
			_quantity = _x select 1;
			_added = false;
			if (!_added && {isClass(configFile >> "CfgWeapons" >> _class)}) then {
				_box addWeaponCargo [_class, _quantity];
				_added = true;
			};
			if (!_added && {isClass(configFile >> "CfgMagazines" >> _class)}) then {
				_box addMagazineCargo [_class, _quantity];
				_added = true;
			};
			if (!_added) then {
				_box addItemCargo [_class, _quantity];
				_added = true;
			};
		} foreach _ammo_list;
	};
} else {
	if (!isDedicated) then {
		if (count (["MSO","FillAmmoBox",[_box, _side,[]]] call ioc_fnc_exec) > 0) then {
			_ammo_filled = true;
		};
	};
	if (!_ammo_filled) then {
		TLOG("TODO: Add some default Ammo Filling");
	};
};
TRACE("End");